﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.LogEntries.SiegeAftermathLogEntry
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.Extensions;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.LogEntries
{
  public class SiegeAftermathLogEntry : LogEntry
  {
    [SaveableField(10)]
    private readonly SiegeAftermathAction.SiegeAftermath _siegeAftermath;
    [SaveableField(20)]
    private readonly Settlement _capturedSettlement;
    [SaveableField(30)]
    private readonly Hero _decisionMaker;
    [SaveableField(40)]
    private readonly bool _playerWasInvolved;

    internal static void AutoGeneratedStaticCollectObjectsSiegeAftermathLogEntry(
      object o,
      List<object> collectedObjects)
    {
      ((LogEntry) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this._capturedSettlement);
      collectedObjects.Add((object) this._decisionMaker);
    }

    internal static object AutoGeneratedGetMemberValue_siegeAftermath(object o)
    {
      return (object) ((SiegeAftermathLogEntry) o)._siegeAftermath;
    }

    internal static object AutoGeneratedGetMemberValue_capturedSettlement(object o)
    {
      return (object) ((SiegeAftermathLogEntry) o)._capturedSettlement;
    }

    internal static object AutoGeneratedGetMemberValue_decisionMaker(object o)
    {
      return (object) ((SiegeAftermathLogEntry) o)._decisionMaker;
    }

    internal static object AutoGeneratedGetMemberValue_playerWasInvolved(object o)
    {
      return (object) ((SiegeAftermathLogEntry) o)._playerWasInvolved;
    }

    public SiegeAftermathLogEntry(
      MobileParty leaderParty,
      IEnumerable<MobileParty> attackers,
      Settlement settlement,
      SiegeAftermathAction.SiegeAftermath siegeAftermath)
    {
      this._siegeAftermath = siegeAftermath;
      this._decisionMaker = leaderParty.LeaderHero;
      this._capturedSettlement = settlement;
      this._playerWasInvolved = false;
      foreach (MobileParty attacker in attackers)
      {
        if (attacker == MobileParty.MainParty)
        {
          this._playerWasInvolved = true;
          break;
        }
      }
    }

    public override ImportanceEnum GetImportanceForClan(Clan clan) => ImportanceEnum.Zero;

    public override void GetConversationScoreAndComment(
      Hero talkTroop,
      bool findString,
      out string comment,
      out ImportanceEnum score)
    {
      score = ImportanceEnum.Zero;
      comment = "";
      if (!this._playerWasInvolved || Hero.MainHero.CurrentSettlement != this._capturedSettlement || !Hero.OneToOneConversationHero.IsNotable)
        return;
      score = ImportanceEnum.VeryImportant;
      if (this._siegeAftermath == SiegeAftermathAction.SiegeAftermath.ShowMercy)
        comment = "str_comment_endplayerbattle_you_stormed_this_city_showed_mercy";
      if (this._siegeAftermath == SiegeAftermathAction.SiegeAftermath.Devastate)
        comment = "str_comment_endplayerbattle_you_stormed_this_city_devastated";
      if (this._siegeAftermath != SiegeAftermathAction.SiegeAftermath.Pillage)
        return;
      comment = "str_comment_endplayerbattle_you_stormed_this_city";
    }

    public override string ToString() => this.GetNotificationText().ToString();

    public TextObject GetNotificationText()
    {
      TextObject to = (TextObject) null;
      if (this._siegeAftermath == SiegeAftermathAction.SiegeAftermath.ShowMercy)
        to = new TextObject("{=wTh00qoj}{HERO.NAME} has showed mercy to {SETTLEMENT}.");
      if (this._siegeAftermath == SiegeAftermathAction.SiegeAftermath.Devastate)
        to = new TextObject("{=NeTp63aU}{HERO.NAME} has devastated {SETTLEMENT}.");
      if (this._siegeAftermath == SiegeAftermathAction.SiegeAftermath.Pillage)
        to = new TextObject("{=VzAqZucZ}{HERO.NAME} has pillaged {SETTLEMENT}.");
      if (this._decisionMaker != null)
        to.SetCharacterProperties("HERO", this._decisionMaker.CharacterObject);
      to.SetTextVariable("SETTLEMENT", this._capturedSettlement.Name);
      return to;
    }
  }
}
